package com.service;

import com.entity.Emp;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PublisherServiceImpl {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsgString(){
        rabbitTemplate.convertAndSend("hello","orderdata");
    }

    public void sendMsgEmp(){
        rabbitTemplate.convertAndSend("hello",new Emp(100,"abc"));
    }

    public void createOrder3(){
        //这里不能发送到队列，无法接收是因为默认交换机是direct类型的，只会发给routingkey完全匹配的队列
        rabbitTemplate.convertAndSend("quick.orange.rabbit","quick.orange.rabbit");
        //指定了交换机，routingkey符合2个绑定，会发给2个队列
        rabbitTemplate.convertAndSend("mytopicA","quick.orange.rabbit","quick.orange.rabbit-topic");

        rabbitTemplate.convertAndSend("mytopicA","quick.orange.rabbit",new Emp(100,"quick.orange.rabbit-topic emp"));
//        rabbitTemplate.convertAndSend("a.orange.b",new Emp(100,"a.orange.b"));
    }
}
